package jehc.djshi.workflow.web;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import io.swagger.annotations.Api;
import jehc.djshi.common.annotation.Auth;
import jehc.djshi.common.base.BasePage;
import jehc.djshi.common.base.BaseResult;
import jehc.djshi.common.entity.OauthAccountEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import jehc.djshi.common.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import com.github.pagehelper.PageInfo;
import jehc.djshi.common.base.BaseAction;
import jehc.djshi.common.base.BaseSearch;
import jehc.djshi.workflow.model.LcFieldHtml;
import jehc.djshi.workflow.service.LcFieldHtmlService;
import javax.annotation.Resource;
/**
 * @Desc 字段html类型
 * @Author 邓纯杰
 * @CreateTime 2022-04-04 18:38:14
 */
@Api(value = "字段html类型",description = "字段html类型", tags = "字段html类型")
@RestController
@RequestMapping("/lcFieldHtml")
public class LcFieldHtmlController extends BaseAction{

	@Resource
	private LcFieldHtmlService lcFieldHtmlService;

	/**
	 * 查询并分页
	 * @param baseSearch
	 */
	@ApiOperation(value="查询并分页", notes="查询并分页")
	@Auth(value = "/lcFieldHtml/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@PostMapping(value="/list")
	public BasePage<List<LcFieldHtml>> getLcFieldHtmlListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<LcFieldHtml> lcFieldHtmlList = lcFieldHtmlService.getLcFieldHtmlListByCondition(condition);
		for(LcFieldHtml lcFieldHtml:lcFieldHtmlList){
			if(!StringUtil.isEmpty(lcFieldHtml.getCreateId())){
				OauthAccountEntity createBy = getAccount(lcFieldHtml.getCreateId());
				if(null != createBy){
					lcFieldHtml.setCreateBy(createBy.getName());
				}
			}
			if(!StringUtil.isEmpty(lcFieldHtml.getUpdateId())){
				OauthAccountEntity modifieBy = getAccount(lcFieldHtml.getUpdateId());
				if(null != modifieBy){
					lcFieldHtml.setModifiedBy(modifieBy.getName());
				}
			}
		}
		PageInfo<LcFieldHtml> page = new PageInfo<LcFieldHtml>(lcFieldHtmlList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	 * 查询单条记录
	 * @param id
	 */
	@ApiOperation(value="查询单条记录", notes="查询单条记录")
	@Auth(value = "/lcFieldHtml/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@GetMapping(value="/get/{id}")
	public BaseResult<LcFieldHtml> getLcFieldHtmlById(@PathVariable("id")String id){
		LcFieldHtml lcFieldHtml = lcFieldHtmlService.getLcFieldHtmlById(id);
		OauthAccountEntity createBy = getAccount(lcFieldHtml.getCreateId());
		if(null != createBy){
			lcFieldHtml.setCreateBy(createBy.getName());
		}
		if(!StringUtil.isEmpty(lcFieldHtml.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(lcFieldHtml.getUpdateId());
			if(null != modifiedBy){
				lcFieldHtml.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(lcFieldHtml);
	}

	/**
	 * 添加
	 * @param lcFieldHtml
	 */
	@ApiOperation(value="添加", notes="添加")
	@PostMapping(value="/add")
	public BaseResult addLcFieldHtml(@RequestBody LcFieldHtml lcFieldHtml){
		int i = 0;
		if(null != lcFieldHtml){
			i=lcFieldHtmlService.addLcFieldHtml(lcFieldHtml);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param lcFieldHtml
	 */
	@ApiOperation(value="修改", notes="修改")
	@PutMapping(value="/update")
	public BaseResult updateLcFieldHtml(@RequestBody LcFieldHtml lcFieldHtml){
		int i = 0;
		if(null != lcFieldHtml){
			i=lcFieldHtmlService.updateLcFieldHtml(lcFieldHtml);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation(value="删除", notes="删除")
	@DeleteMapping(value="/delete")
	public BaseResult delLcFieldHtml(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=lcFieldHtmlService.delLcFieldHtml(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 查询列表
	 * @return
	 */
	@ApiOperation(value="查询列表", notes="查询列表")
	@Auth(value = "/lcFieldHtml/find",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@GetMapping(value="/find")
	public BaseResult<List<LcFieldHtml>> getFieldTypeList(){
		Map<String, Object> condition = new HashMap<>();
		List<LcFieldHtml> lcFieldHtmlList = lcFieldHtmlService.getLcFieldHtmlListByCondition(condition);
		return new BaseResult(lcFieldHtmlList);
	}
}
